package part10.controller;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wcj
 * @Date 2021/5/19 19:41
 * @Version 1.0
 */
public class Controller {

    private List<BaseEvent> eventList = new ArrayList<>();

    public void addEvent(BaseEvent e) {
        eventList.add(e);
    }

    public void run() {
        while (eventList.size() > 0) {
            for (BaseEvent e : new ArrayList<BaseEvent>(eventList)) {
                if (e.ready()) {
                    System.out.println(e);
                    e.action();
                    eventList.remove(e);
                }
            }
        }
    }
}
